package design.action.memento;

/**
 * @author zxs
 * @since 2020/05/29
 */
public abstract class AbstractOriginator implements Originator {

    protected final Caretaker caretaker;
    protected final String name;

    public AbstractOriginator(String name,Caretaker caretaker){
        this.name = name;
        this.caretaker = caretaker;
    }

    @Override
    public void storeMemento() {
        caretaker.saveMemento(name,createMemento());
    }

    @Override
    public void recoveryMemento() {
        recoveryMemento(caretaker.getMemento(name));
    }

    protected abstract Memento createMemento();
    protected abstract void recoveryMemento(Memento memento);
}
